package ne.analyzer.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import ne.analyzer.util.Utils;

/**
 * 用户信息按钮
 * 
 * @author sunny
 *
 */
public class UserInfoPanel extends Composite {

	public UserInfoPanel(Composite parent, int style, String text, String imgPath) {
		super(parent, style);
		this.setLayout(new FormLayout());
		Label pic = new Label(this, SWT.CENTER);
		FormData infoP = new FormData();
		infoP.top = new FormAttachment(0, 4);
		infoP.left = new FormAttachment(0, 2);
		infoP.right = new FormAttachment(100, -2);
		infoP.bottom = new FormAttachment(100, -25);
		pic.setLayoutData(infoP);
		if (imgPath == null) {
			imgPath = "/icons/avatar.png";
		}
		pic.setImage(Utils.getImageFromClassPath(imgPath));
		FormData infoD = new FormData();
		infoD.top = new FormAttachment(pic, 4);
		infoD.left = new FormAttachment(0, 2);
		infoD.right = new FormAttachment(100, -2);
		infoD.bottom = new FormAttachment(100, -2);
		Label info = new Label(this, SWT.CENTER);
		info.setLayoutData(infoD);
		info.setText(text);
	}

	public UserInfoPanel(Composite parent, int style, String text) {
		this(parent, style, text, null);
	}
}
